package com.example.mychat.Utils;

import com.example.mychat.Controller.WebSocketConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

//@CrossOrigin(origins = "http://localhost:7000")
@CrossOrigin(origins = "*")
@Configuration
public class WebSocketConfig implements WebSocketConfigurer {
    //    @Bean
//    public ServerEndpointExporter serverEndpointExporter(){
//        return new ServerEndpointExporter();
//    }
    @Autowired
    private WebSocketConnection webSocketConnection;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry
                .addHandler(webSocketConnection, "Websocket")
                //允许跨域
                .setAllowedOrigins("*");

    }
}
